package com.george.order.service.impl;

import com.george.common.api.feign.stock.StockServiceFeign;
import com.george.common.api.feign.user.UserServiceFeign;
import com.george.common.exception.BaseException;
import com.george.order.service.OrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Create By George on /2023/4/10
 * description: 订单服务接口实现
 *
 * @author George
 */
@Slf4j
@AllArgsConstructor
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private UserServiceFeign userService;

    @Resource
    private StockServiceFeign stockService;

    /**
     * 创建订单
     *
     * @param userId
     * @param orderId
     * @return void
     * @author George
     * @date 2023/4/10 1:08
     */
    @Override
    public void createOrder(String userId,String orderId) {
        log.info("创建订单，订单号：{}",orderId);
        if(StringUtils.isEmpty(orderId)){
            throw new BaseException("订单号不能为空");
        }else{
            userService.getUserInfoById(Long.getLong(userId));
            stockService.outStock(orderId);
            System.out.println("创建订单成功，订单号：" + orderId);
        }
    }
}
